package com.soul.admin.controller;

import com.soul.admin.service.ManageService;
import com.soul.model.vo.PageResult;
import com.soul.model.vo.UserInfoVoAge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManageController {
    
    @Autowired
    private ManageService manageService;

    /**
     * 用户管理 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity findPage(@RequestParam(defaultValue = "1") Long page, @RequestParam(defaultValue = "10",value = "pagesize") Long pageSize) {
        return ResponseEntity.ok(manageService.findPage(page,pageSize));
    }

    /**
     * 查询用户详情
     * @return
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity getUserInfo(@PathVariable Long userId){
        return ResponseEntity.ok(manageService.findById(userId));
    }

    /**
     * 查询指定用户发布的所有视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Long page, @RequestParam(defaultValue = "10") Long pagesize, Long uid ) {
        return ResponseEntity.ok(manageService.findAllVideos(page,pagesize,uid));
    }

    //查询动态
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Long page, @RequestParam(defaultValue = "10") Long pagesize, Long uid,Integer state) {
        return ResponseEntity.ok(manageService.findAllMovements(page,pagesize,uid,state));
    }

    /**
     *  用户冻结操作
     * @param params 参数对象
     * @return Map message作为key
     */
    @RequestMapping(path = "/users/freeze",method = RequestMethod.POST)
    public ResponseEntity freeze(@RequestBody Map<String,String> params){
        String userId = params.get("userId"); // 被冻结用户id
        String freezingTime = params.get("freezingTime"); // 冻结时间，1为冻结3天，2为冻结7天，3为永久冻结
        String freezingRange = params.get("freezingRange"); // 冻结范围，1为冻结登录，2为冻结发言，3为冻结发布动态
        String reasonsForFreezing = params.get("reasonsForFreezing"); // 冻结原因
        String frozenRemarks = params.get("frozenRemarks"); // 冻结备注
        return ResponseEntity.ok(manageService.freeze(userId,freezingTime,freezingRange,reasonsForFreezing,frozenRemarks)); // message
    }

    /**
     *  用户解冻操作
     * @param params 参数对象
     * @return Map message作为key
     */
    @RequestMapping(path = "/users/unfreeze",method = RequestMethod.POST)
    public ResponseEntity unfreeze(@RequestBody Map<String,String> params){
        String userId = params.get("userId"); // 被解冻用户id
        String frozenRemarks = params.get("frozenRemarks"); // 解冻备注
        String reasonsForThawing = params.get("reasonsForThawing"); // 解冻原因
        return ResponseEntity.ok(manageService.unfreeze(userId,frozenRemarks,reasonsForThawing)); // message
    }
}